<template>
  <div>
    <!--      搜索组件-->
    <SearchModle dataKey="studentParents" @searchFn="searchFn"></SearchModle>
    <!--      end-->
    <div class="mb-10">
      <div class="toplineBox">
        <p class="numberline toplineBox-right">总{{page.total}}条</p>
      </div>
    </div>
    <!--本体列表，数据 -->
    <div class="table-body">
      <div class="table-body-box">
        <el-table
            ref="multipleTable"
            :data="arryList"
            :stripe="tableStyle.tableStripe"
            :border="tableStyle.tableBorder"
            tooltip-effect="dark"
            header-cell-class-name="table-text-c"
            style="width: 100%">
          <el-table-column
              prop="name"
              label="证照名称"
              width="120"
              align="center">
          </el-table-column>
          <el-table-column
              prop="create_time"
              label="当前持有人"
              align="center">
            <template slot-scope="scope">
              {{scope.row.student?scope.row.student.name:'未知'}}
            </template>
          </el-table-column>
          <el-table-column
              label="申请人"
              align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.relation">{{scope.row.relation}}</span>
              <span v-else>未匹配</span>
            </template>
          </el-table-column>
          <el-table-column
              prop="mobile_phone"
              label="用途"
              align="center">
          </el-table-column>
          <el-table-column
              prop="role"
              label="借用日期"
              align="center">
            <template slot-scope="scope">
              <div class="wx-user-box" v-if="scope.row.openid">
                <el-popover
                    placement="left"
                    width="200"
                    trigger="hover"
                >
                    <span v-if="scope.row.openid" class="wx-user-box-line">
                      <img :src="scope.row.wx.pic" alt="">{{ scope.row.wx.user_name }}
                     </span>
                  <span slot="reference" class="btn-wx">已绑定</span>
                </el-popover>
                <span class="delet-wx" @click="deletWx(scope.$index)">(解除绑定)</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
              prop="mobile_phone"
              label="归还日期"
              align="center">
          </el-table-column>
          <el-table-column
              prop="mobile_phone"
              label="剩余天数"
              align="center">
          </el-table-column>
          <el-table-column
              prop="mobile_phone"
              label="补充说明"
              align="center">
          </el-table-column>
          <el-table-column
              prop="mobile_phone"
              label="归还照片"
              align="center">
          </el-table-column>
          <el-table-column
              prop="mobile_phone"
              label="状态"
              align="center">
          </el-table-column>
        </el-table>
      </div>
    </div>
    <!--工具条 分页-->
    <el-col :span="24" class="toolbar">
      <el-pagination
          background
          layout="total, prev, pager, next"
          :total="page.total"
          :page-size="page.pagesize"
          @current-change="handleSizeChange">
      </el-pagination>
    </el-col>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
export default {
  components: {
  },
  data () {
    return {
      handleSelection: [],
      arryList: [], // 页面数据列表
      // 设置table样式
      tableStyle: tableoption,
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      indexOption: '',
      classesListNew: [],
      sectionList: [],
      classesList: [],
      editForm: {
        mobile_phone: '',
        p: '',
        name: '', // 	整型 	必填 	1 	- 	名称
        class_id: '', //  	整型 	必填 	1 	- 	户籍所属镇（街）
        section_id: '' //  	整型 	必填 	1 	- 	户口
      },
      // 搜索组件
      searchForm: {},
      parentsVisible: false,
      parentsOption: ''
    }
  },
  created () {
    this.InitFn()
  },
  methods: {
    // 初始化
    InitFn () {
      this.searchForm.p = this.page.pageindex
      this.$fetch(this.api.admin_parents_index, this.searchForm).then((response) => {
        if (response.code === 0) {
          this.arryList = JSON.parse(JSON.stringify(response.list.data))
          this.page.total = response.list.total
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    // 分页
    handleSizeChange (val) {
      this.page.pageindex = val
      this.InitFn()
    },
    // 搜索组件
    searchFn(option) {
      this.page.pageindex = 1
      this.searchForm = option
      this.InitFn()
    },
    addStudent (row) {
      this.parentsOption = row;
      this.parentsVisible = true;
      //     this.parentsOption = row
      // let id = row || ''
      // this.$router.push('/studentParentsdetail?editId=' + id)
    },
    deletWx(index) {
      let n = this;
      this.$confirm('确认解除'+this.arryList[index].name+'微信绑定, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.closeBinding(index,n.arryList[index].id)
      }).catch(() => {
      })
    },
    closeBinding(index,id){
      let n = this;
      this.$post(this.api.patents.closeWxBind, {id: id}).then((response) => {
        if (response.code === 0) {
          n.arryList[index].openid = ''
          this.$message({
            type: 'success',
            message: '解绑成功!'
          })
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    }
  },
  mounted () {},
  // 缓存机制 star
  beforeRouteEnter (to, from, next) {
    // 利用路由元信息中的 meta 字段设置变量，方便在各个位置获取。这就是为什么在 meta 中定义 isNeedRefresh。
    // 当从详情页返回时，将 isNeedRefresh 设为 false，表示不刷新数据
    if (to.meta.isNeedRefresh) {
      this.InitFn() // 详情页面需要刷新数据
    }
    next()
  },
  beforeRouteLeave (to, from, next) {
    // isNeedRefresh 进入页面判断是否需要刷新
    if (to.meta.isNeedRefresh) {
      from.meta.keepAlive = true
    } else {
      from.meta.keepAlive = false
    }
    next()
  }
  // 缓存机制 end
}
</script>

<style scoped>

.wx-user-box-line img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin-right: 5px;
}

.wx-user-box-line {
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-wx {
  cursor: pointer;
  padding: 5px;
}

.btn-wx:hover {
  color: #1b8de5;
  text-decoration: underline;
}

.delet-wx {
  color: red;
  cursor: pointer;
}

.delet-wx:hover {
  text-decoration: underline;
}
</style>
